package tt.love.hw.action;


import java.util.Date;
import java.util.List;


import tt.love.hw.common.ActionContext;
import tt.love.hw.common.ViewRender;
import tt.love.hw.jdo.Comment;
import tt.love.hw.service.ApplicationService;
import tt.love.hw.service.CommentService;

public class CommentAction {
	private ApplicationService applicationService;
	private CommentService commentService;
	
	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}
	
	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
	}



	public ViewRender createComment(ActionContext actionContext){	
		Comment comment = (Comment)actionContext.get("comment");
		comment.setCommentDate(new Date());
		comment.setCommentUserId(actionContext.getUserSessionInfo().getUserid());
		commentService.createComment(comment);
		applicationService.updateNewCommentBy(comment.getCommentUserId(), comment.getAppId());
		return new ViewRender("/process/viewComments.tt?appId="+comment.getAppId());
	}
	public ViewRender viewComments(ActionContext actionContext){
		String appId = (String)actionContext.get("appId");
		List<Comment> commentList = commentService.getCommentList(appId);
		applicationService.removeNewCommentBy(actionContext.getUserSessionInfo().getUserid(), appId);
		actionContext.put("commentList", commentList);
		return new ViewRender("/process/app_comments.jsp");
	}
	
}
